package com.dajie.pt.controller.util;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.dajie.common.framework.spring.controller.BaseController;
import com.dajie.group.helper.GroupInviteHelper;
import com.dajie.group.helper.GroupInviteParam;
import com.dajie.group.helper.GroupInviteTypeEnum;

@Controller
@RequestMapping("util")
public class UtilController extends BaseController
{

	protected static final Logger LOGGER = LoggerFactory.getLogger(UtilController.class);
	
	
	@RequestMapping("gencode")
	public String genCode(HttpServletRequest request,
			@RequestParam(value="groupid")Integer groupId,
			@RequestParam(value="gouid") Integer ouid,
			@RequestParam(value="iuid") Integer iuid,
			@RequestParam(value="tid") Integer topicId
			)
	{
		LOGGER.info("groupid:{},gouid:{},iuid:{},tid:{}",groupId,ouid,iuid,topicId);
		String code = GroupInviteHelper.generateGroupInviteCode(new GroupInviteParam(groupId, GroupInviteTypeEnum.INVITE, ouid, iuid));
		StringBuffer stb= new StringBuffer("redirect:http://www.dajie.com/group/edm/acceptinvite?code=");
		stb.append(code);
		stb.append("&redir=http://www.dajie.com/group/");
		stb.append(groupId);
		stb.append("/topic/");
		stb.append(topicId);
		LOGGER.info("util.gencode.url:{}",stb.toString());
		return stb.toString();
	}
}
